﻿using System.Diagnostics;

using EMan.BL;
using EMan.BL.EnterpriseStructure;
using EMan.BL.EnterpriseStructure.Jobs;
using EMan.BL.EnterpriseStructure.StructureTree;
using EMan.BL.WorkTasks;
using EMan.Common;
using EMan.Common.DependencyInjection;
using EMan.Common.EnterpriseStructure;
using EMan.GUI;
using EMan.GUI.EditStructure;
using EMan.Interface;
using EMan.Interface.EnterpriseStructure;
using EMan.Interface.EnterpriseStructure.Departments;
using EMan.Interface.EnterpriseStructure.Employees;
using EMan.Interface.EnterpriseStructure.Jobs;
using EMan.Interface.WorkTasks;
using EMan.WCF;

using TrueCode.Core.Diagnostics;
using TrueCode.Core.Validation;
using TrueCode.DependencyManager;
using TrueCode.DependencyManager.Extensions;

namespace EMan.DependencyInjection.Scoping
{
  public static class GlobalScopeContainerProvider
  {
    public static Container GetContainer()
    {
      var container = ClientFactory.CreateContainer();
      container.Register< Diagnostic >().As< IDiagnostic >().AsSingleton()
          .Using.Parameters( "eManClient", SourceLevels.All )
      
      .Register< Validator >().As< IValidator >().AsSingleton()
                               
      .Register< EManServiceProxy >().As< IEMan >( false ).As< IEnterpriseStructure >( false ).AsSingleton()
        .Using.FactoryMethod( bs => EManServiceProxy.Create() )
      
      // ------------------------- Views -----------------------
      .Register<MainView>(  ).As<IMainView>()
      .Register< StructureTreeEditorView >().As< IStructureTreeEditorView >()
      .Register< JobListEditorView >()     .As< IJobListEditorView >()

      .Register< EditDepartmentView >().As< IDepartmentEditorGuiElement >()
      .Register< EditJobView >().As< IJobEditorGuiElement >()

      .Register< EmployeeEditorView >().As< IEmployeeEditorGuiElement >().As< IEmployeeEditorView >()

      .Register< JobChooserView >().As< IJobChooserGuiElement >()
      // -------------------------------------------------------

      // ------------------------- Presenters -----------------------
      .Register< StructureTreeEditorPresenter >().As< IStructureTreeEditorPresenter >()
      .Register< DepartmentEditorPresenter >().As< IDepartmentEditorPresenter >()
      .Register< EmployeeEditorPresenter >().As< IEmployeeEditorPresenter >()
      
      .Register< JobListEditorPresenter >().As< IJobListEditorPresenter >()
      .Register< JobEditorPresenter >().As< IJobEditorPresenter >()
      .Register< JobChooserPresenter >().As< IJobChooserPresenter >()
      .Register< MainPresenter >(  ).As<IMainPresenter>()
      .Register< WorkTaskEditorPresenter>(  ).As<IWorkTaskEditorPresenter>()
      // -------------------------------------------------------
      ;

      return container;
    }
  }
}